package mwt.xml.xdbforms.xforms.impl;

import java.util.HashMap;
import java.util.Map;
import mwt.xml.xdbforms.dbms.exceptions.TypeNotFoundException;
import mwt.xml.xdbforms.xforms.TypeHandler;

public class MySQLTypeHandler implements TypeHandler {
    private Map<String, String> map = new HashMap<String, String>(24);

    public MySQLTypeHandler (){
        this.map.put("varchar", "xsd:string");
        this.map.put("int", "xsd:decimal");
        this.map.put("int unsigned", "xsd:decimal");
        this.map.put("tinyint", "xsd:decimal");
        this.map.put("text", "xsd:string");
        this.map.put("date", "xsd:date");
        this.map.put("smallint", "xsd:decimal");
        this.map.put("mediumint", "xsd:decimal");
        this.map.put("float", "xsd:float");
        this.map.put("double", "xsd:double");
        this.map.put("decimal", "xsd:decimal");
        this.map.put("datetime", "xsd:dateTime");
        this.map.put("timestamp", "xsd:dateTime");
        this.map.put("time", "xsd:time");
        this.map.put("year", "xsd:gYear");
        this.map.put("char", "xsd:string");
        this.map.put("tinyblob", "xsd:string");
        this.map.put("tinytext", "xsd:string");
        this.map.put("blob", "xsd:string");
        this.map.put("mediumblob", "xsd:string");
        this.map.put("mediumtext", "xsd:string");
        this.map.put("longblob", "xsd:string");
        this.map.put("bit", "xsd:string");
        this.map.put("tinyint", "xsd:decimal");
        this.map.put("binary", "xsd:string");
        this.map.put("bool", "xsd:boolean");
        this.map.put("bigint", "xsd:decimal");
        this.map.put("longtext", "xsd:string");
    }

    public String getSchemaTypeName(String typeName) throws TypeNotFoundException {
        typeName = typeName.toLowerCase();
        if (!this.map.containsKey(typeName)) {
            throw new TypeNotFoundException("Il tipo " + typeName + " non è gestito!");
        }

        return this.map.get(typeName);
    }
}